package unit_7;
import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class DisplayButtonMessage extends JFrame {
Elevator myElevator = new Elevator();
int i=0;
static JPanel panel;
public DisplayButtonMessage(){
JButton[] buttons = new JButton[10];
panel=new JPanel(new GridLayout(4,6));
String  b[]={"1","2","3","4","5","6","7","8","9","10"};
for(i = 0; i < buttons.length; i++) 
{
	buttons[i] = new JButton(b[i]);
	buttons[i].setSize(80, 80);
	buttons[i].setActionCommand(b[i]);
	buttons[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
  String choice = e.getActionCommand();
 JOptionPane.showMessageDialog(null, "You have Chosen Floor: "+choice);
 {
 int userChoice = Integer.parseInt(choice);
	if(userChoice > myElevator.TOP_FLOOR)
	{
		System.out.println("Incorrect Value Please Try Again");
	}else if(userChoice < myElevator.MIN_FLOORS)
	{
		System.out.println("Incorrect Value Please Try Again");		
	}else if(myElevator.currentFloor > userChoice)
	{
		try {
			myElevator.goDown(userChoice);
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}else if(myElevator.currentFloor < userChoice)
	{
		try {
			myElevator.goUp(userChoice);
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
}
}
});
panel.add(buttons[i]);
}
}
public static void main(String[]args){
DisplayButtonMessage frame=new DisplayButtonMessage();
frame.add(panel);
frame.pack();
frame.setVisible(true);
 }
}


